package demo1.dao.impl;

import demo1.dao.AccountDao;
import demo1.dao.mapper.Rm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;
@Repository
public class AccountDaoImpl implements AccountDao {
    @Autowired
    JdbcTemplate tmp;

    @Override
    public void update(String name, Double money) {
        String sql="update account set money=money+? where name=?";
        tmp.update(sql,money,name);
    }

    @Override
    public Double selectMoney(String name) {
        String sql="select money from account where name=?";
        List<Double> list=tmp.query(sql,new Rm(),name);
        return list.isEmpty()?null:list.get(0);
    }
}
